def sm3(std):
    dict1 = {}
    dict2 = {}

    for i in range(len(std)):
        list1 = dict1.keys()
        if std[i] in list1:
            dict1[std[i]] = dict1[std[i]]+1
        else:
            dict1[std[i]] = 1

    dict3 = sorted(dict1.items(), key=lambda x: x[1], reverse=True)

    for i in range(3):
        key1 = max(dict1, key=dict1.get)
        dict2[key1] = dict1[key1]
        del dict1[key1]

    return print(' 排序后的字典：\n', dict(dict3),
                 '\n\n',
                 '字典中次数出现最多的三个元素：\n', dict2)


text = "abcevaefegsgdghfdefavbdr"
sm3(text)
# 最后用py的文件来上传哈